﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace cwtrock.util
{
    class SimpleTool
    {
        /// <summary>
        /// 验证输入框的输入内容
        /// </summary>
        /// <param name="textbox">输入框控件</param>
        /// <param name="length">最大输入长度</param>
        /// <param name="controlName">输入框的名称</param>
        /// <returns>true验证通过，false验证不通过</returns>
        public static bool validaing(ErrorProvider errorProvider1, TextBox textbox, int length, string controlName)
        {
            bool result = false;
            if (textbox.TextLength == 0)
            {
                errorProvider1.SetError(textbox, controlName + "不允许为空！");
                textbox.SelectAll();
                textbox.Focus();

            }
            else if (textbox.TextLength > length)
            {
                errorProvider1.SetError(textbox, "请输入小于" + length.ToString() + "个字符的" + controlName + "！");
                textbox.SelectAll();
                textbox.Focus();
            }
            else
            {
                errorProvider1.SetError(textbox, "");
                result = true;
            }
            return result;
            
        }

        // 判断空值
        public static bool isEmpty(string str) {
            if (str == null || "".Equals(str))
            {
                return true;
            }
            return false;
        }

        // 判断非值
        public static bool isNotEmpty(string str)
        {
            return !isEmpty(str);
        }
    }
}
